package com.li.controller;

import com.li.pojo.Dept;
import com.li.service.impl.DeptServiceImpl;
import com.li.util.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Map;

@Controller
@RequestMapping("dept")
public class DeptController {
    @Autowired
    DeptServiceImpl deptService;


    @RequestMapping("query")
    public String query( Model model,@RequestParam Map<String,Object> params) {
        String name= (String) params.get("name");
        PageUtils page = deptService.queryPage(params);
        model.addAttribute("name",name);
        model.addAttribute("sln",page);
        return "dep/dept";
    }

    @GetMapping("/dperAdd")
    public String period() {
        return "dep/dadd";
    }

    @PostMapping("/dadd")
    public String add(Dept dept) {
        deptService.saveOrUpdate(dept);
        return "redirect:dept/query" ;
    }


    @GetMapping("/ddel")
    public String  del(Integer id) {
        deptService.removeById(id);
        return "redirect:dept/query";
    }

    @GetMapping("/dedit")
    public String edit( Integer id, Model model) {
        Dept dept=deptService.getById(id);
        model.addAttribute("as",dept);
        return "dep/dadd";
    }


}
